<?php
declare(strict_types=1);

namespace Modules\Production\Http\Controllers;

use Catch\Base\CatchController as Controller;
use App\Services\UnitService;use Modules\Base\Repository\MaterialRepository;use Modules\Production\Models\ProductionReportDetail;
use Illuminate\Http\Request;


class ProductionReportDetailController extends Controller
{
    public function __construct(
        protected readonly ProductionReportDetail $model
    ){}

    /**
     * @param Request $request
     * @return mixed
     */
    public function index(): mixed
    {
        $list = $this->model->getList()->toArray();
        foreach ($list['data'] as &$item){
            $item['material'] = MaterialRepository::findMaterial($item['material_no']);
        }
        return $list;
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        return $this->model->storeBy($request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function show($id)
    {
        return $this->model->firstBy($id);
    }

    /**
     * @param Request $request
     * @param $id
     * @return mixed
     */
    public function update($id, Request $request)
    {
        return $this->model->updateBy($id, $request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->model->deleteBy($id);
    }
}
